package com.qlk.odcinterface.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.odcinterface.domain.PmsCouponItem;
import com.qlk.odcinterface.domain.query.PmsCouponItemQuery;
import com.qlk.odcinterface.manager.PmsCouponItemManager;
import com.qlk.odcinterface.service.PmsCouponItemService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;
 
/**
 * PmsCouponItemService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 14:11:36
 * 
 */
@Service
public class PmsCouponItemServiceImpl implements PmsCouponItemService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsCouponItemServiceImpl.class);

    @Autowired
    private PmsCouponItemManager pmsCouponItemManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.batchInsert")
    public boolean insert(List<PmsCouponItem> pmsCouponItemList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsCouponItemList)) {
                resultFlag = pmsCouponItemManager.insert(pmsCouponItemList);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.insert")
    public boolean insert(PmsCouponItem pmsCouponItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponItem) {
                if (pmsCouponItemManager.exist(pmsCouponItem)) {
                    throw new ExistedException();
                }
                resultFlag = pmsCouponItemManager.insert(pmsCouponItem);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsCouponItemServiceImpl#insert failed, pmsCouponItem has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.update")
    public boolean update(PmsCouponItem pmsCouponItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponItem && null != pmsCouponItem.getId()) {
                resultFlag = pmsCouponItemManager.update(pmsCouponItem);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.queryPmsCouponItemList")
    public List<PmsCouponItem> queryPmsCouponItemList(PmsCouponItemQuery queryBean) {
        List<PmsCouponItem> pmsCouponItemList = null;
        try {
            pmsCouponItemList = pmsCouponItemManager.queryPmsCouponItemList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#queryPmsCouponItemList has error.", e);
        }
        return pmsCouponItemList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.queryPmsCouponItemListWithPage")
    public List<PmsCouponItem> queryPmsCouponItemListWithPage(PmsCouponItemQuery queryBean, PageUtil pageUtil) {
        List<PmsCouponItem> pmsCouponItemList = null;
        try {
            pmsCouponItemList = pmsCouponItemManager.queryPmsCouponItemListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#queryPmsCouponItemListWithPage has error.", e);
        }
        return pmsCouponItemList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.delete")
    public boolean delete(PmsCouponItem pmsCouponItem) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponItem && null != pmsCouponItem.getId()) {
                resultFlag = pmsCouponItemManager.delete(pmsCouponItem);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.batchDelete")
    public boolean delete(PmsCouponItem[] pmsCouponItems) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponItems && pmsCouponItems.length > 0) {
                resultFlag = pmsCouponItemManager.delete(pmsCouponItems);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponItemService.getPmsCouponItemById")
    public PmsCouponItem getPmsCouponItemById(Long id) {
        PmsCouponItem pmsCouponItem = null;
        try {
            if (null != id) {
                pmsCouponItem = pmsCouponItemManager.getPmsCouponItemById(id);
            } else {
                LOG.warn("PmsCouponItemServiceImpl#getPmsCouponItemById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponItemServiceImpl#getPmsCouponItemById has error.", e);
        }
        return pmsCouponItem;
    }
}

